-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[11.x] Introduce method Rule::array()
#51250
Conversation
@Jacobs63 why not use Rule::enum() for matching against an enum's cases? |
The
Unlike
They're two different validation rules. |
My bad! I misunderstood the usecase, thanks for the explaination though. |
What's the difference between |
|
@decadence Thank you. I wasn't aware there's already an |
* [11.x] Introduce method `Rule::array()` * CS fixes * Add `func_get_args` test * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
This PR introduces a new
array
method to\Illuminate\Validation\Rule
.Currently, it is often cumbersome to validate multiple array keys through the
array
rule. At the same time, if intending to using constants, or enums, we may end up in defining our rule such as:The goal of this change is to improve code readability and prevent uncaught typos when validating array keys, but to also improve the existing functionalities by introducing support for
Arrayable
& lists of enums.The newly introduced
ArrayRule
works very similar to the already existingIn
rule, by stringifying to the originalarray
string rule, introducing no breaking changes.In summary, the following is now possible: